package com.zenchn.schedule;

import com.zenchn.model.TSysScheduleTask;
import com.zenchn.model.TSysScheduleTaskExample;
import com.zenchn.service.ScheduleTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时任务初始化载入队列 spring 启动后 执行
 *
 * @author panbingqi
 * @date 2021-06-01
 **/
@Component
@Order(10)
public class SchedulerInit implements ApplicationRunner {

    private static final Logger logger = LoggerFactory.getLogger(SchedulerInit.class);


    @Resource
    private ScheduleTaskService scheduleTaskService;

    @Resource
    private SchedulerService schedulerService;



    @Override
    public void run(ApplicationArguments args) throws Exception {



        TSysScheduleTaskExample example=new TSysScheduleTaskExample();
        example.createCriteria().andIsEnableEqualTo(true);
        List<TSysScheduleTask> scheduleTaskList=scheduleTaskService.selectByExample(example);
        if (null!=scheduleTaskList && !scheduleTaskList.isEmpty()){
            for (TSysScheduleTask scheduleTask:scheduleTaskList){
                schedulerService.enableSchedule(scheduleTask);
            }
        }
    }

}
